<template>
  <div class="app-container">
    <!-- 商品管理 -->
    <el-form v-show="showSearch" ref="queryRef" :model="queryParams" :inline="true">
      <el-form-item label="商品名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入商品名称"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品分类" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="商品分类"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="c in cgstatus"
            :key="c.value"
            :label="c.label"
            :value="c.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否享受会员卡折扣" prop="status">
        <el-select
          v-model="queryParams.status"
          clearable
          style="width: 240px"
        >
          <el-option label="全部" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>  
    <el-row :gutter="10" class="mb8">
      <el-col>
        <el-button
          v-hasPermi="['oam:venue:add']"
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
        >新建商品</el-button>
        <el-button type="primary" plain>商品单位设置</el-button>
        <el-button type="primary" plain>商品入库</el-button>
        <el-button type="primary" plain>商品盘点</el-button>
        <el-button type="primary" plain>导出商品列表</el-button>
        <el-button type="primary" plain>商品导入</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row> 
    <!-- 表格数据 -->
    <el-table v-loading="loading" @selection-change="handleSelectionChange">
      <el-table-column type="index" />
      <el-table-column label="商品图片" prop="cardTypeStr" width="120" />
      <el-table-column label="商品名称" prop="cardTypeStr" width="120" />
      <el-table-column label="商品编码" prop="cardTypeStr" width="120" />
      <el-table-column label="商品分类" prop="cardTypeStr" width="120" />
      <el-table-column label="是否享受会员卡折扣" prop="cardTypeStr" width="120" />
      <el-table-column label="零售价" prop="cardTypeStr" width="120" />
      <el-table-column label="参考进价" prop="cardTypeStr" width="120" />
      <el-table-column label="商品单位" prop="cardTypeStr" width="120" />
      <el-table-column label="总库存" prop="cardTypeStr" width="120" />
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding">
        <template #default="scope">
          <el-button type="text" @click="record(scope.row)">编辑</el-button>
          <el-button type="text" @click="recharge(scope.row)">删除</el-button>
          <el-button type="text" @click="recharge(scope.row)">详情</el-button>
          <el-button type="text" @click="recharge(scope.row)">上架</el-button>
          <el-button type="text" @click="recharge(scope.row)">下架</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @pagination="getList"
    />
	
    <!-- 新建/编辑 -->
    <el-dialog v-model="open" :title="title" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="roleRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="商品名称" prop="roleName">
          <el-input v-model="form.roleName" placeholder="请输入场馆名称" />
        </el-form-item>
        <el-form-item label="商品分类" prop="roleName">
          <el-select />
          <el-button>+</el-button>
        </el-form-item>
        <el-form-item label="商品编码" prop="roleName">
          <el-input v-model="form.roleName" />
          <el-button>生成编码</el-button>
        </el-form-item>
        <el-form-item label="商品单位" prop="roleName">
          <el-select /><el-button>+</el-button>
        </el-form-item>
        <el-form-item label="排序编号" prop="roleName">
          <el-input />
        </el-form-item>
        <el-form-item label="是否享受会员卡折扣" prop="roleName">
          <el-radio-group v-model="radio">
            <el-radio :label="3">是</el-radio>
            <el-radio :label="6">否</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">保 存</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
	  
    </el-dialog>
	
    <!-- 商品入库 -->
    <el-dialog v-model="open" :title="title" width="1000px" append-to-body :close-on-click-modal="false">
      <el-row>
        <el-col :span="12">
          <div>
            <el-select>
              <option>全部</option>
            </el-select>
            <el-input />
          </div>	
          <el-table v-loading="loading">
            <el-table-column type="index" />
            <el-table-column label="商品分类" prop="cardTypeStr" width="120" />
            <el-table-column label="商品名称" prop="cardTypeStr" width="120" />
            <el-table-column label="进价" prop="cardTypeStr" width="120" />				
          </el-table>
        </el-col>
        <el-col :span="12">
          <h3>已选商品</h3>
          <el-table>
            <el-table-column label="名称" prop="cardTypeStr" width="120" />
            <el-table-column label="进价" prop="cardTypeStr" width="120" />				
            <el-table-column label="数量" prop="cardTypeStr" width="120" />				
            <el-table-column label="操作" prop="cardTypeStr" width="120" />				
          </el-table>
          <el-input type="textarea" />
        </el-col>
			
      </el-row>
	  
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">入库</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
	
    <!-- 盘点 -->
    <el-dialog v-model="open" :title="title" width="800px" append-to-body :close-on-click-modal="false">
      <div>
        <el-button>选择商品</el-button>
      </div>
      <el-table>
        <el-table-column label="分类" prop="cardTypeStr" width="120" />
        <el-table-column label="条码" prop="cardTypeStr" width="120" />				
        <el-table-column label="名称" prop="cardTypeStr" width="120" />				
        <el-table-column label="进价" prop="cardTypeStr" width="120" />				
        <el-table-column label="单位" prop="cardTypeStr" width="120" />				
        <el-table-column label="库存量" prop="cardTypeStr" width="120" />				
        <el-table-column label="盘点数量" prop="cardTypeStr" width="120">
          <template #default="scope">
            <el-input-number v-model="num" :min="1" :max="10" label="描述文字" @change="handleChange" /> 
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template #default="scope">
            <el-button type="text" @click="record(scope.row)">移除</el-button>
          </template>  
        </el-table-column>
      </el-table>
	  
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">盘点</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
	
  </div>
  
</template>

<script setup>
const { proxy } = getCurrentInstance()	
	
const cgstatus = ref([{ value: '0', label: '冻结' }, { value: '1', label: '解冻' }])
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref('')
const open = ref(false)
const loading = ref(true)
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: undefined
  },
  rules: {
		
  }
})
const { queryParams, form, rules } = toRefs(data)
// 获取列表
function getList() {
  loading.value = true
}

function reset() {
  form.value = {}
  proxy.resetForm('roleRef')
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef')
  handleQuery()
}
/** 删除按钮操作 */
function handleDelete(row) {
  const roleIds = row.roleId || ids.value
  proxy.$modal.confirm('是否确认删除角色编号为"' + roleIds + '"的数据项?').then(function() {
    return delRole(roleIds)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess('删除成功')
  }).catch(() => {})
}
function handleAdd() {
  reset()
  open.value = true
  title.value = '新建场馆'
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.roleId)
  single.value = selection.length != 1
  multiple.value = !selection.length
}
function handleChange(value) {
  console.log(value)
}

getList()
</script>

<style scoped lang="scss">

</style>
